/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cbaServer;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Rente
 */
public class RMIConnections {

    private BankServer bs;
    private final String rmiAddressCBA = "rmi://localhost/bankserverCBA";
    private final String rmiAddressRemote = "rmi://localhost/bankserverRemote";

  

    public RMIConnections(BankServer bs) {
        try {
            this.bs = bs;
         
            LocateRegistry.createRegistry(1099);
        } catch (RemoteException ex) {
            Logger.getLogger(RMIConnections.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void criaLigacaoRMI(String tipo) {
        try {
            if (tipo.equals("remote")) {
                Naming.bind(rmiAddressRemote, new RemoteOperations(bs));
                System.out.println("RMI Server for Remote ready");
            } else if (tipo.equals("cba")) {
                Naming.bind(rmiAddressCBA, new CBAOperations(bs));
                System.out.println("RMI Server for CBA ready");
            }
        } catch (Exception re) {
            re.printStackTrace();
        }

    }
}
